/**
  ******************************************************************************
  * @file    main.c 
  * @author  hai
  * @version V1.0
  * @date    2017/8/14
  * @brief   Main program body
  ******************************************************************************
  */  
#include "Sys.h"
#include "app_cam_ts1.h"
#include "app_schd_task.h"
#include "app_param.h"
#include "app_cam_zero.h"
#include "app_touch_screen.h"

#include "bq76930.h"
#include "soft_iic.h"
#include "ads1230.h"

#include "app_wakeup.h"

#include "w25qx.h" 


static void show_logger(void)
{
	printf("                     _ 		\r\n");
	printf("                    | |		\r\n");
	printf("   ___ _ __ ___   __| |		\r\n");
	printf("  / __| '_ ` _ \\ / _` |	\r\n");
	printf("  \\__ \\ | | | | | (_| |	\r\n");
	printf("  |___/_| |_| |_|\\__,_|	\r\n");
	printf("==============sys start now\r\n");
	printf("==============sys start now\r\n");
	printf("==============sys start now\r\n\r\n");
}

void reboot(void)
{
	printf("\r\n	reboot now.\r\n");
	printf("	reboot now.\r\n");
	printf("	reboot now.\r\n");
	
	delay_ms(100);
	NVIC_SystemReset ();
}

static void bsp_init(void)
{	
	RCC_Configuration();
	Systick_Init();
	SystemCoreClockUpdate();   
	//IWDG_Init(4, 1000); 

	loopdelay_init();    
	mem_init();
	usart_init();

#if (EN_DEBUG)
	uart_setup(USART_DEBUG, 115200, 256, 1024);	
#endif 
	usmart_dev.init(72);
	show_logger();


	led_init(); 
	CAN_setup();

	//SBUS_SETUP;
	//UARTCHN_SETUP;
	//PWM_SETUP;

	//camif_init(); 
	
	IIC_Init();
	bq76930_init();
	ads1230_init();

	app_wakeup_init();

	w25qx_init();

	//SYS_START;
}

static void get_sys_time(void)
{
	const unsigned char cRevisionDate[12] = __DATE__;
	const unsigned char cRevisionTime[16] = __TIME__;

	delay_ms(300);
	printf("\r\nsys bulid time: %s %s\r\n", cRevisionDate, cRevisionTime);
	delay_ms(10);
}



int main(void)
{    
	// NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x4000);  //STM32F1 remap vector table.
	bsp_init();

	get_sys_time();
	param_init();

	/*-- for cam-tsx-pos -------------------*/
	//app_cam_ts1_schd_init();
	/*-- end --------------------------------*/

	/*-- for cam-ZERO-pos -------------------*/
	//app_cam_zero_schd_init();
	/*-- end --------------------------------*/

	/*-- public ----------------------------*/
	schd_task_register(usart_publish_loop,20);
	schd_task_register(can_sendpkg_loop,20);
	//schd_task_register(camif_heart_loop,400);

	schd_task_register(led_scan,10);

	schd_task_register(usmart_dev.scan,15);
	/*-- end --------------------------------*/
	
	while(1)
	{     
		schd_task_poll();
	}
    
}



